package testview.zhen.com.myapplication.hencoder.practice_draw1

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.os.Build
import androidx.annotation.RequiresApi
import android.util.AttributeSet
import android.util.DisplayMetrics
import android.view.View

class Practice2DrawCircleView : View {

    var paint = Paint()

    var halfHeight:Int = 0
    var widths:Int = 0

    override fun getMinimumHeight(): Int {
        return super.getMinimumHeight()
    }

    fun setPaint(style:Paint.Style,color: Int,with:Float = 2.0f): Paint {
        paint.style = style
        paint.color = color
        paint.strokeWidth = with
        return paint
    }

    constructor(context: Context) : super(context) {
      var dm:DisplayMetrics =  context.resources.displayMetrics
        halfHeight =  dm.heightPixels/2
        widths = dm.widthPixels/2
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {}

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {}

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)



        canvas.drawOval(100.0f,0.0f,500.0f,400.0f,paint)
        setPaint(Paint.Style.STROKE,Color.BLACK)
        canvas.drawOval(600f,0.0f,1000.0f,400.0f,paint)
        setPaint(Paint.Style.FILL,Color.BLUE)
        canvas.drawOval(100f,400.0f,500.0f,800.0f,paint)
        setPaint(Paint.Style.STROKE,Color.BLACK,20.0f)
        canvas.drawOval(600f,400.0f,900.0f,700.0f,paint)

        //        练习内容：使用 canvas.drawCircle() 方法画圆
        //        一共四个圆：1.实心圆 2.空心圆 3.蓝色实心圆 4.线宽为 20 的空心圆
    }
}
